<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2018/3/14
 * Time: 13:08
 */

namespace app\index\controller;
use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;


class ScApi extends Common
{
    //商品同步接口
    //http://xltscapi.shared123.cn/
    public function GoodsSave($data,$type){
       $u = 'http://xltscapi.shared123.cn/index/goods/save';
       $data['type'] = $type;
       $rd =  $this->httpPost($u,$data);
      

    }
    public function GoodsDel($id){
        $u = 'http://xltscapi.shared123.cn/index/goods/del?id='.$id;
        $rd =  $this->httpGet($u);
    }
    private function httpGet($url) {
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_HEADER,0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1 );
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
    }
    private function httpPost($url,$postData) {
        $post_string = '';
        foreach ($postData as $k=>$v){
            $post_string.=$k.'='.$v.'&';
        }
        $post_string  = substr($post_string, 0, -1);

        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_HEADER,0);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1 );
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
    }
    /**
     * Curl版本
     * 使用方法：
     * $post_string = "app=request&version=beta";
     * request_by_curl('http://www.qianyunlai.com/restServer.php', $post_string);
     */
//    function request_by_curl($remote_server, $post_string) {
//        $ch = curl_init();
//        curl_setopt($ch, CURLOPT_URL, $remote_server);
//        curl_setopt($ch, CURLOPT_POSTFIELDS, 'mypost=' . $post_string);
//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//        curl_setopt($ch, CURLOPT_USERAGENT, "qianyunlai.com's CURL Example beta");
//        $data = curl_exec($ch);
//        curl_close($ch);
//
//        return $data;
//    }
}
